<template>
  <div class="content">
    <div class="tags">
      <span ref="all" @click="showAll()">全部{{all}}</span>
      <span ref="good" @click="showGood()">推荐{{good}}</span>
      <span ref="bad" @click="showBad()">吐槽{{bad}}</span>
    </div>
    <div class="content-lists">
      <div class="list" v-for="(item, index) in commentlist" :key="index">
        <div class="avatar">
          <img :src="item.avatar" alt="" />
        </div>
        <div class="list-content">
          <div class="time">{{ item.time || item.rateTime }}</div>
          <div class="name">{{ item.username }}</div>
          <div class="star">
            <el-rate
              font-size="10px"
              v-model="item.score"
              disabled
              text-color="#ff9900"
              score-template="{value}"
            >
            </el-rate>
            <!-- <span v-show="item.deliveryTime !== ''"
              >{{ item.deliveryTime }}分钟送达</span
            > -->
          </div>
          <div>{{ item.text }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "CommentsLists",
  data() {
    return {
      value1: 3.5,
      commentlist: [],
      all:0,
      good:0,
      bad:0
    };
  },
  props: ["ratings"],
  methods: {
    showAll() {
      this.commentlist = this.ratings;
      this.$refs.all.className = "selected"
      this.$refs.good.className = ""
      this.$refs.bad.className = ""
    },
    showGood() {
      this.$refs.good.className = "selected"
      this.$refs.all.className = ""
      this.$refs.bad.className = ""
      this.commentlist = [];
      this.ratings.forEach((element) => {
        if (element.rateType == 0) {
          this.commentlist.push(element);
        }
      });
    },
    showBad() {
      this.$refs.bad.className = "selected"
      this.$refs.all.className = ""
      this.$refs.good.className = ""
      this.commentlist = [];
      this.ratings.forEach((element) => {
        if (element.rateType == 1) {
          this.commentlist.push(element);
        }
      });
    },
  },
  mounted() {

    this.showAll();

    this.ratings.forEach(element => {
      this.all ++
      if(element.rateType == 0){
        this.good ++
      }
      if(element.rateType == 1){
        this.bad ++
      }
    });
  },
};
</script>

<style scoped>
.content {
  background: #fff;
  font-size: 12px;
}
.tags {
  height: 50px;
  border-bottom: 1px solid #eee;
  display: flex;
}
.tags span {
  display: inline-block;
  width: 60px;
  height: 25px;
  border: 1px solid #dedede;
  border-radius: 10px;
  margin: 10px;
  line-height: 25px;
  text-align: center;
}
.list {
  /* height: 90px; */
  /* background: lavender; */
  padding: 10px;
  display: flex;
  position: relative;
  border-bottom: 1px solid #eee;
}

.avatar {
  width: 38px;
  height: 33px;
  border-radius: 50%;
  background: lavenderblush;
  overflow: hidden;
}
.avatar img {
  width: 100%;
  height: 100%;
}
.time {
  position: absolute;
  top: 5px;
  right: 20px;
  font-size: 11px;
  color: #888;
}
.star {
  display: flex;
}
.star span {
  padding-left: 10px;
}
.list-content {
  width: 100%;
  padding-left: 15px;
}
.selected {
  background: rgb(228, 228, 228);
}
</style>